package com.example.learning1;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.NotificationCompat;

import android.annotation.SuppressLint;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.util.Printer;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.PopupWindow;
import android.widget.ProgressBar;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    private static final String TAG = "leo";
    private ProgressBar progressBar_load;
    private NotificationManager manager;
    private Notification notification;
    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        /////////////////////popupwindow/////


        Button button_popwindow=findViewById(R.id.button_popupwindow);
        button_popwindow.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                @SuppressLint("ResourceType") View popview=getLayoutInflater().inflate(R.id.xml2,null);

                PopupWindow popupWindow=new PopupWindow(popview, ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);
                popupWindow.showAsDropDown(v);
            }
        });
        /////////////////////notification模块///////////////
        manager=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
        if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.O){
            NotificationChannel channel = new NotificationChannel("leo","测试",NotificationManager.IMPORTANCE_HIGH);
            manager.createNotificationChannel(channel);

        }
        notification=new NotificationCompat.Builder(this,"leo")
                .setContentTitle("+bbbplay")
                .setContentText("快来玩啊")
                .setSmallIcon(R.drawable.ic_baseline_accessibility_24)
                .build();
        Button button_send_notification=findViewById(R.id.button_notification);
        button_send_notification.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                manager.notify(1,notification);
            }
        });

        ///////////////////////////////加载模块///////////////
        progressBar_load=findViewById(R.id.progress_horizontal_load);//定义加载进度条
        Button button_add_load=findViewById(R.id.button_add_load);
        button_add_load.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int progress=progressBar_load.getProgress();
                progress+=10;
                progressBar_load.setProgress(progress);
            }
        });
        ///////////////////////////按钮相应模块
        //点击事件，按钮一
        Button button1=findViewById(R.id.button1);
        button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Log.e(TAG, "onClick: ");//打印函数哈哈哈
//                setContentView(xml2);
            }
        });
        //长按时间
        button1.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                Log.e(TAG, "onLongClick: ");
                return false;
            }
        });
        //按钮触摸事件,MotionEvent内部有好几种的触摸事件
        button1.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                Log.e(TAG, "onTouch: "+event.getAction());
                return false;//如果改为true就只执行这一个事件，等于事件被消耗了
            }
        });
    }
}